/*
 *    Copyright (c) 2018-2025, cloud All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: cloud
 */
package com.fuyao.cloud.asset.receivelist.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuyao.cloud.asset.entity.receive.Receive;
import com.fuyao.cloud.asset.entity.receive.ReceiveList;
import com.fuyao.cloud.asset.receivelist.mapper.ReceiveListMapper;
import com.fuyao.cloud.asset.receivelist.service.ReceiveListService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 资产领用清单
 *
 * @author liyue
 * @date 2021-12-16 10:41:17
 */
@Service
public class ReceiveListServiceImpl extends ServiceImpl<ReceiveListMapper, ReceiveList> implements ReceiveListService {

	@Transactional
	@Override
	public void saveUpdateReceiveList(Receive entity) {
		List<ReceiveList> receiveList = entity.getReceiveList();
		if (CollUtil.isNotEmpty(receiveList)) {
			receiveList.forEach(re->{
				re.setParentId(entity.getId());
				re.setParentCaseid(entity.getCaseid());
				re.setStatus(Integer.parseInt(entity.getStatus()));
			});
			this.saveOrUpdateBatch(receiveList);
		}
	}
}
